home *** CD-ROM | disk | FTP | other *** search
/ Enter 2007 April / ENTER_CD_04_07.iso / Internet / WinHTTrack 3.23 / httrack-3.23.exe / {app} / src / htswizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-08  |  31.6 KB  |  906 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: httrack.c subroutines:                                 */
  34. /*       wizard system (accept/refuse links)                    */
  35. /* Author: Xavier Roche                                         */
  36. /* ------------------------------------------------------------ */
  37.  
  38. #include "htswizard.h"
  39. #include "htsdefines.h"
  40.  
  41. /* specific definitions */
  42. #include "htsbase.h"
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <ctype.h>
  47. /* END specific definitions */
  48.  
  49. // version 1 pour httpmirror
  50. // flusher si on doit lire peu α peu le fichier
  51. #define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->errlog); }
  52.  
  53. // pour allΘger la syntaxe, des raccourcis sont crΘΘs
  54. #define urladr   (liens[ptr]->adr)
  55. #define urlfil   (liens[ptr]->fil)
  56.  
  57. // libΘrer filters[0] pour insΘrer un ΘlΘment dans filters[0]
  58. #define HT_INSERT_FILTERS0 {\
  59.   int i;\
  60.   if (*filptr > 0) {\
  61.     for(i = (*filptr)-1 ; i>=0 ; i--) {\
  62.       strcpybuff(filters[i+1],filters[i]);\
  63.     }\
  64.   }\
  65.   strcpybuff(filters[0],"");\
  66.   (*filptr)++;\
  67.   (*filptr)=minimum((*filptr),filter_max);\
  68. }
  69.  
  70.  
  71.  
  72. /*
  73. httrackp opt     bloc d'options
  74. int ptr,int lien_tot,lien_url** liens
  75.                              relatif aux liens
  76. char* adr,char* fil
  77.                              adresse/fichier α tester
  78. char** filters,int filptr,int filter_max
  79.                              relatif aux filtres
  80. robots_wizard* robots
  81.                              relatif aux robots
  82. int* set_prio_to
  83.                              callback obligatoire "capturer ce lien avec prio=N-1"
  84. int* just_test_it
  85.                              callback optionnel "ne faire que tester ce lien Θventuellement"
  86. retour:
  87.                0 acceptΘ
  88.                1 refusΘ
  89.                -1 pas d'avis
  90. */
  91. int hts_acceptlink(httrackp* opt,
  92.                    int ptr,int lien_tot,lien_url** liens,
  93.                    char* adr,char* fil,
  94.                    char*** ptrfilters,int* filptr,int filter_max,
  95.                    robots_wizard* robots,
  96.                    int* set_prio_to,
  97.                    int* just_test_it) {
  98.   
  99.   int forbidden_url=-1;
  100.   int meme_adresse;
  101.   char** filters = *ptrfilters;
  102.   int may_set_prio_to=0;
  103.  
  104.   // -------------------- PHASE 0 --------------------
  105.  
  106.   /* Infos */
  107.   if ((opt->debug>1) && (opt->log!=NULL)) {
  108.     fspc(opt->log,"debug"); fprintf(opt->log,"wizard test begins: %s%s"LF,adr,fil);
  109.     test_flush;
  110.   }
  111.   
  112.   /* Already exists? Then, we know that we knew that this link had to be known */
  113.   if (adr[0] != '\0'
  114.     && fil[0] != '\0'
  115.     && opt->hash != NULL
  116.     && hash_read((hash_struct*)opt->hash, adr, fil, 1) >= 0
  117.     ) {
  118.     return 0;  /* Yokai */
  119.   }
  120.   
  121.   // -------------------- PHASE 1 --------------------
  122.  
  123.   /* Doit-on traiter les non html? */
  124.   if ((opt->getmode & 2)==0) {    // non on ne doit pas
  125.     if (!ishtml(fil)) {  // non il ne faut pas
  126.       //adr[0]='\0';    // ne pas traiter ce lien, pas traiter
  127.       forbidden_url=1;    // interdire rΘcupΘration du lien
  128.       if ((opt->debug>1) && (opt->log!=NULL)) {
  129.         fspc(opt->log,"debug"); fprintf(opt->log,"non-html file ignored at %s : %s"LF,adr,fil);
  130.         test_flush;
  131.       }
  132.       
  133.     }
  134.   }
  135.   
  136.   /* Niveau 1: ne pas parser suivant! */
  137.   if (ptr>0) {
  138.     if (liens[ptr]->depth <= 1) {
  139.       forbidden_url=1;    // interdire rΘcupΘration du lien
  140.       if ((opt->debug>1) && (opt->log!=NULL)) {
  141.         fspc(opt->log,"debug"); fprintf(opt->log,"file from too far level ignored at %s : %s"LF,adr,fil);
  142.         test_flush;
  143.       }
  144.     }
  145.   }
  146.  
  147.   /* en cas d'Θchec en phase 1, retour immΘdiat! */
  148.   if (forbidden_url==1) {
  149.     return forbidden_url;
  150.   }
  151.   
  152.   // -------------------- PHASE 2 --------------------
  153.  
  154.   // ------------------------------------------------------
  155.   // doit-on traiter ce lien?.. vΘrifier droits de dΘplacement
  156.   meme_adresse=strfield2(adr,urladr);
  157.   if ((opt->debug>1) && (opt->log!=NULL)) {
  158.     fspc(opt->log,"debug"); 
  159.     if (meme_adresse) 
  160.       fprintf(opt->log,"Compare addresses: %s=%s"LF,adr,urladr);
  161.     else
  162.       fprintf(opt->log,"Compare addresses: %s!=%s"LF,adr,urladr);
  163.     test_flush;
  164.   }
  165.   if (meme_adresse) {  // mΩme adresse 
  166.     {  // tester interdiction de descendre
  167.       // MODIFIE : en cas de remontΘe puis de redescente, il se pouvait qu'on ne puisse pas atteindre certains fichiers
  168.       // problΦme: si un fichier est virtuellement accessible via une page mais dont le lien est sur une autre *uniquement*..
  169.       char tempo[HTS_URLMAXSIZE*2];
  170.       char tempo2[HTS_URLMAXSIZE*2];
  171.       
  172.       // note (up/down): on calcule α partir du lien primaire, ET du lien prΘcΘdent.
  173.       // ex: si on descend 2 fois on peut remonter 1 fois
  174.       
  175.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  176.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  177.           if ((opt->debug>1) && (opt->log!=NULL)) {
  178.             fspc(opt->log,"debug"); fprintf(opt->log,"build relative links to test: %s %s (with %s and %s)"LF,tempo,tempo2,liens[liens[ptr]->premier]->fil,liens[ptr]->fil);
  179.             test_flush;
  180.           }
  181.           
  182.           // si vient de primary, ne pas tester lienrelatif avec (car host "diffΘrent")
  183.           /*if (liens[liens[ptr]->premier] == 0) {   // vient de primary
  184.           }
  185.           */
  186.           
  187.           // NEW: finalement OK, sauf pour les moved repΘrΘs par link_import
  188.           // PROBLEME : annulΘ a cause d'un lien Θventuel isolΘ acceptΘ..qui entrainerait un miroir
  189.           
  190.           // (test mΩme niveau (NOUVEAU α cause de certains problΦmes de filtres non intΘgrΘs))
  191.           // NEW
  192.           if ( (!strchr(tempo+1,'/')) || (!strchr(tempo2+1,'/')) ) {
  193.             if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  194.               forbidden_url=0;
  195.               if ((opt->debug>1) && (opt->log!=NULL)) {
  196.                 fspc(opt->log,"debug"); fprintf(opt->log,"same level link authorized: %s%s"LF,adr,fil);
  197.                 test_flush;
  198.               }
  199.             }
  200.           }
  201.           
  202.           // down
  203.           if ( (strncmp(tempo,"../",3)) || (strncmp(tempo2,"../",3)))  {   // pas montΘe sinon ne nbous concerne pas
  204.             int test1,test2;
  205.             if (!strncmp(tempo,"../",3))
  206.               test1=0;
  207.             else
  208.               test1 = (strchr(tempo +((*tempo =='/')?1:0),'/')!=NULL);
  209.             if (!strncmp(tempo2,"../",3))
  210.               test2=0;
  211.             else
  212.               test2 = (strchr(tempo2+((*tempo2=='/')?1:0),'/')!=NULL);
  213.             if ( (test1) && (test2) ) {   // on ne peut que descendre
  214.               if ((opt->seeker & 1)==0) {  // interdiction de descendre
  215.                 forbidden_url=1;
  216.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  217.                   fspc(opt->log,"debug"); fprintf(opt->log,"lower link canceled: %s%s"LF,adr,fil);
  218.                   test_flush;
  219.                 }
  220.               } else {    // autorisΘ α priori - NEW
  221.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  222.                   forbidden_url=0;
  223.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  224.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  225.                     test_flush;
  226.                   }
  227.                 }
  228.               }
  229.             } else if ( (test1) || (test2) ) {   // on peut descendre pour accΘder au lien
  230.               if ((opt->seeker & 1)!=0) {  // on peut descendre - NEW
  231.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  232.                   forbidden_url=0;
  233.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  234.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  235.                     test_flush;
  236.                   }
  237.                 }
  238.               }
  239.             }
  240.           }
  241.           
  242.           
  243.           // up
  244.           if ( (!strncmp(tempo,"../",3)) && (!strncmp(tempo2,"../",3)) ) {    // impossible sans monter
  245.             if ((opt->seeker & 2)==0) {  // interdiction de monter
  246.               forbidden_url=1;
  247.               if ((opt->debug>1) && (opt->log!=NULL)) {
  248.                 fspc(opt->log,"debug"); fprintf(opt->log,"upper link canceled: %s%s"LF,adr,fil);
  249.                 test_flush;
  250.               }
  251.             } else {       // autorisΘ α monter - NEW
  252.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  253.                 forbidden_url=0;
  254.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  255.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  256.                   test_flush;
  257.                 }
  258.               }
  259.             }
  260.           } else if ( (!strncmp(tempo,"../",3)) || (!strncmp(tempo2,"../",3)) ) {    // Possible en montant
  261.             if ((opt->seeker & 2)!=0) {  // autorisΘ α monter - NEW
  262.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  263.                 forbidden_url=0;
  264.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  265.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  266.                   test_flush;
  267.                 }
  268.               }
  269.             }  // sinon autorisΘ en descente
  270.           }
  271.           
  272.           
  273.         } else {
  274.           if (opt->errlog) {
  275.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  276.             test_flush;
  277.           }
  278.         }
  279.       } else {
  280.         if (opt->errlog) {
  281.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  282.           test_flush;
  283.         }
  284.       }
  285.       
  286.     }  // tester interdiction de descendre?
  287.     
  288.     {  // tester interdiction de monter
  289.       char tempo[HTS_URLMAXSIZE*2];
  290.       char tempo2[HTS_URLMAXSIZE*2];
  291.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  292.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  293.         } else {
  294.           if (opt->errlog) { 
  295.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  296.             test_flush;
  297.           }
  298.           
  299.         }
  300.       } else {
  301.         if (opt->errlog) { 
  302.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  303.           test_flush;
  304.         }
  305.         
  306.       }
  307.     }   // fin tester interdiction de monter
  308.     
  309.   } else {    // adresse diffΘrente, sortir?
  310.     
  311.     //if (!opt->wizard) {    // mode non wizard
  312.     // doit-on traiter ce lien?.. vΘrifier droits de sortie
  313.     switch((opt->travel & 255)) {
  314.     case 0: 
  315.       if (!opt->wizard)    // mode non wizard
  316.         forbidden_url=1; break;    // interdicton de sortir au dela de l'adresse
  317.     case 1: {              // sortie sur le mΩme dom.xxx
  318.       int i=strlen(adr)-1;
  319.       int j=strlen(urladr)-1;
  320.       while( (i>0) && (adr[i]!='.')) i--;
  321.       while( (j>0) && (urladr[j]!='.')) j--;
  322.       i--; j--;
  323.       while( (i>0) && (adr[i]!='.')) i--;
  324.       while( (j>0) && (urladr[j]!='.')) j--;
  325.       if ((i>0) && (j>0)) {
  326.         if (!strfield2(adr+i,urladr+j)) {   // !=
  327.           if (!opt->wizard) {   // mode non wizard
  328.             //printf("refused: %s\n",adr);
  329.             forbidden_url=1;  // pas mΩme domaine  
  330.             if ((opt->debug>1) && (opt->log!=NULL)) {
  331.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign domain link canceled: %s%s"LF,adr,fil);
  332.               test_flush;
  333.             }
  334.           }
  335.           
  336.         } else {
  337.           if (opt->wizard) {   // mode wizard
  338.             forbidden_url=0;  // mΩme domaine  
  339.             if ((opt->debug>1) && (opt->log!=NULL)) {
  340.               fspc(opt->log,"debug"); fprintf(opt->log,"same domain link authorized: %s%s"LF,adr,fil);
  341.               test_flush;
  342.             }
  343.           }
  344.         }
  345.         
  346.       } else
  347.         forbidden_url=1;
  348.             } 
  349.       break;  
  350.     case 2: {                      // sortie sur le mΩme .xxx
  351.       int i=strlen(adr)-1;
  352.       int j=strlen(urladr)-1;
  353.       while( (i>0) && (adr[i]!='.')) i--;
  354.       while( (j>0) && (urladr[j]!='.')) j--;
  355.       if ((i>0) && (j>0)) {
  356.         if (!strfield2(adr+i,urladr+j)) {   // !-
  357.           if (!opt->wizard) {   // mode non wizard
  358.             //printf("refused: %s\n",adr);
  359.             forbidden_url=1;  // pas mΩme .xx  
  360.             if ((opt->debug>1) && (opt->log!=NULL)) {
  361.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign location link canceled: %s%s"LF,adr,fil);
  362.               test_flush;
  363.             }
  364.           }
  365.         } else {
  366.           if (opt->wizard) {   // mode wizard
  367.             forbidden_url=0;  // mΩme domaine  
  368.             if ((opt->debug>1) && (opt->log!=NULL)) {
  369.               fspc(opt->log,"debug"); fprintf(opt->log,"same location link authorized: %s%s"LF,adr,fil);
  370.               test_flush;
  371.             }
  372.           }
  373.         }
  374.       } else forbidden_url=1;     
  375.             } 
  376.       break;
  377.     case 7:                 // everywhere!!
  378.       if (opt->wizard) {   // mode wizard
  379.         forbidden_url=0;
  380.         break;
  381.       }
  382.     }  // switch
  383.     
  384.     // ANCIENNE POS -- rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink)
  385.     
  386.   }  // fin test adresse identique/diffΘrente
  387.  
  388.   // -------------------- PHASE 3 --------------------
  389.  
  390.   // rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink) (nvelle pos)
  391.   if (opt->nearlink) {
  392.     if (!ishtml(fil)) {  // non html
  393.       //printf("ok %s%s\n",ad,fil);
  394.       forbidden_url=0;    // autoriser
  395.       may_set_prio_to=1+1; // set prio to 1 (parse but skip urls) if near is the winner
  396.       if ((opt->debug>1) && (opt->log!=NULL)) {
  397.         fspc(opt->log,"debug"); fprintf(opt->log,"near link authorized: %s%s"LF,adr,fil);
  398.         test_flush;
  399.       }
  400.     }
  401.   }
  402.   
  403.   // -------------------- PHASE 4 --------------------
  404.   
  405.   // ------------------------------------------------------
  406.   // Si wizard, il se peut qu'on autorise ou qu'on interdise 
  407.   // un lien spΘcial avant mΩme de tester sa position, sa hiΘrarchie etc.
  408.   // peut court-circuiter le forbidden_url prΘcΘdent
  409.   if (opt->wizard) { // le wizard entre en action..
  410.     //
  411.     int question=1;         // poser une question                            
  412.     int force_mirror=0;     // pour mirror links
  413.     int filters_answer=0;   // dΘcision prise par les filtres
  414.     char l[HTS_URLMAXSIZE*2];
  415.     char lfull[HTS_URLMAXSIZE*2];
  416.     
  417.     if (forbidden_url!=-1) question=0;  // pas de question, rΘsolu
  418.     
  419.     // former URL complΦte du lien actuel
  420.     strcpybuff(l,jump_identification(adr));
  421.     if (*fil!='/') strcatbuff(l,"/");
  422.     strcatbuff(l,fil);
  423.     // full version (http://foo:bar@www.foo.com/bar.html)
  424.     if (!link_has_authority(adr))
  425.       strcpybuff(lfull,"http://");
  426.     else
  427.       lfull[0]='\0';
  428.     strcatbuff(lfull,adr);
  429.     if (*fil!='/') strcatbuff(lfull,"/");
  430.     strcatbuff(lfull,fil);
  431.     
  432.     // tester filters (URLs autorisΘes ou interdites explicitement)
  433.     
  434.     // si lien primaire on saute le joker, on est pas lΘmur
  435.     if (ptr==0) {  // lien primaire, autoriser
  436.       question=1;    // la question sera rΘsolue automatiquement
  437.       forbidden_url=0;
  438.       may_set_prio_to=0;    // clear may-set flag
  439.     } else {
  440.       int jok;
  441.       // filters, 0=sait pas 1=ok -1=interdit
  442.       {
  443.         int jokDepth1=0,jokDepth2=0;
  444.         int jok1=0,jok2=0;
  445.         jok1  = fa_strjoker(filters,*filptr,lfull,NULL,NULL,&jokDepth1);
  446.         jok2 =  fa_strjoker(filters,*filptr,l,    NULL,NULL,&jokDepth2);
  447.         if (jok2 == 0)       // #2 doesn't know
  448.           jok = jok1;        // then, use #1
  449.         else if (jok1 == 0)  // #1 doesn't know
  450.           jok = jok2;        // then, use #2
  451.         else if (jokDepth1 >= jokDepth2)  // #1 matching rule is "after" #2, then it is prioritary
  452.           jok = jok1;
  453.         else                              // #2 matching rule is "after" #1, then it is prioritary
  454.           jok = jok2;
  455.       }
  456.  
  457.       if (jok == 1) {   // autorisΘ
  458.         filters_answer=1;  // dΘcision prise par les filtres
  459.         question=0;    // ne pas poser de question, autorisΘ
  460.         forbidden_url=0;  // URL autorisΘe
  461.         may_set_prio_to=0;    // clear may-set flag
  462.         if ((opt->debug>1) && (opt->log!=NULL)) {
  463.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit authorized link: link %s at %s%s"LF,l,urladr,urlfil);
  464.           test_flush;
  465.         }
  466.       } else if (jok == -1) {
  467.         filters_answer=1;  // dΘcision prise par les filtres
  468.         question=0;    // ne pas poser de question:
  469.         forbidden_url=1;   // URL interdite
  470.         if ((opt->debug>1) && (opt->log!=NULL)) {
  471.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  472.           test_flush;
  473.         }
  474.       }  // sinon on touche α rien
  475.     }
  476.     
  477.     // vΘrifier mode mirror links
  478.     if (question) {
  479.       if (opt->mirror_first_page) {    // mode mirror links
  480.         if (liens[ptr]->precedent==0) {  // parent=primary!
  481.           forbidden_url=0;    // autorisΘ
  482.           may_set_prio_to=0;    // clear may-set flag
  483.           question=1;         // rΘsolution auto
  484.           force_mirror=5;     // mirror (5)
  485.           if ((opt->debug>1) && (opt->log!=NULL)) {
  486.             fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit mirror link: link %s at %s%s"LF,l,urladr,urlfil);
  487.             test_flush;
  488.           }
  489.         }
  490.       }
  491.     }
  492.  
  493.     // vΘrifier rΘcursivitΘ extΘrieure
  494.     if ((question) && (ptr>0) && (!force_mirror)) {
  495.       if (opt->extdepth>0) {
  496.         // *set_prio_to = opt->extdepth + 1;
  497.         *set_prio_to = opt->extdepth + 1;
  498.         forbidden_url=0;    // autorisΘ
  499.         may_set_prio_to=0;    // clear may-set flag
  500.         question=0;         // rΘsolution auto
  501.         if ((opt->debug>1) && (opt->log!=NULL)) {
  502.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) ambiguous link accepted (external depth): link %s at %s%s"LF,l,urladr,urlfil);
  503.           test_flush;
  504.         }
  505.       }
  506.     }  
  507.     
  508.     // on doit poser la question.. peut on la poser?
  509.     // (oui je sais quel preuve de dΘlicatesse, merci merci)      
  510.     if ((question) && (ptr>0) && (!force_mirror)) {
  511.       if (opt->wizard==2) {    // Θliminer tous les liens non rΘpertoriΘs comme autorisΘs (ou inconnus)
  512.         question=0;
  513.         forbidden_url=1;
  514.         if ((opt->debug>1) && (opt->log!=NULL)) {
  515.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) ambiguous forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  516.           test_flush;
  517.         }
  518.       }
  519.     }
  520.     
  521.     // vΘrifier robots.txt
  522.     if (opt->robots) {
  523.       int r = checkrobots(robots,adr,fil);
  524.       if (r == -1) {    // interdiction
  525. #if DEBUG_ROBOTS
  526.         printf("robots.txt forbidden: %s%s\n",adr,fil);
  527. #endif
  528.         // question rΘsolue, par les filtres, et mode robot non strict
  529.         if ((!question) && (filters_answer) && (opt->robots == 1) && (forbidden_url!=1)) {
  530.           r=0;    // annuler interdiction des robots
  531.           if (!forbidden_url) {
  532.             if ((opt->debug>1) && (opt->log!=NULL)) {
  533.               fspc(opt->log,"debug"); fprintf(opt->log,"Warning link followed against robots.txt: link %s at %s%s"LF,l,adr,fil);
  534.               test_flush;
  535.             }
  536.           }
  537.         }
  538.         if (r == -1) {    // interdire
  539.           forbidden_url=1;
  540.           question=0;
  541.           if ((opt->debug>1) && (opt->log!=NULL)) {
  542.             fspc(opt->log,"debug"); fprintf(opt->log,"(robots.txt) forbidden link: link %s at %s%s"LF,l,adr,fil);
  543.             test_flush;
  544.           }
  545.         }
  546.       }
  547.     }
  548.     
  549.     if (!question) {
  550.       if ((opt->debug>1) && (opt->log!=NULL)) {
  551.         if (!forbidden_url) {
  552.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) shared foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  553.         } else {
  554.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) cancelled foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  555.         }
  556.         test_flush;
  557.       }
  558. #if BDEBUG==3
  559.       printf("at %s in %s, wizard says: url %s ",urladr,urlfil,l);
  560.       if (forbidden_url) printf("cancelled"); else printf(">SHARED<");
  561.       printf("\n");
  562. #endif 
  563.     }
  564.  
  565.     /* en cas de question, ou lien primaire (enregistrer autorisations) */
  566.     if (question || (ptr==0)) {
  567. #if HTS_ANALYSTE
  568.       char* s;
  569. #else
  570.       char s[4];
  571. #endif
  572.       int n=0;
  573.       
  574.       // si primaire (plus bas) alors ...
  575.       if ((ptr!=0) && (force_mirror==0)) {
  576.         HTS_REQUEST_START;
  577.         HT_PRINT("\n");
  578.         HT_PRINT("At "); HT_PRINT(urladr); HT_PRINT(", there is a link ("); HT_PRINT(adr); HT_PRINT("/"); HT_PRINT(fil); HT_PRINT(") which goes outside the address."LF);
  579.         HT_PRINT("What should I do? (press a key + enter)"LF LF);
  580.         HT_PRINT("* Ignore all further links" LF);
  581.         HT_PRINT("0 Ignore this link (default if empty entry)"LF);
  582.         HT_PRINT("1 Ignore directory and lower structures"LF);
  583.         HT_PRINT("2 Ignore all domain"LF);
  584.         //HT_PRINT("3 (Ignore location, not implemented)\n");
  585.         HT_PRINT(LF);
  586.         HT_PRINT("4 Get only this page/link"LF);
  587.         HT_PRINT("5 Mirror this link (useful)"LF);
  588.         HT_PRINT("6 Mirror links located in the same domain"LF);
  589.         HT_PRINT(LF);
  590. //#if HTS_ANALYSTE!=2
  591. //HT_PRINT("! View extract of html code where the link is located"LF);
  592. //#endif
  593.         HTS_REQUEST_END;
  594. #if HTS_ANALYSTE
  595.           {
  596.             char tempo[HTS_URLMAXSIZE*2];
  597.             tempo[0]='\0';
  598.             strcatbuff(tempo,adr);
  599.             strcatbuff(tempo,"/");
  600.             strcatbuff(tempo,fil);
  601.             s=hts_htmlcheck_query3(tempo);
  602.           }
  603. #else
  604.         do {
  605.           io_flush; linput(stdin,s,2);
  606. #endif
  607.           if (strnotempty(s)==0)  // entrΘe
  608.             n=0;
  609.           else if (isdigit((unsigned char)*s))
  610.             sscanf(s,"%d",&n);
  611.           else {
  612.             switch(*s) {
  613.             case '*': n=-1; break;
  614.             case '!': n=-999; {
  615.               /*char *a;
  616.               int i;                                    
  617.               a=copie_de_adr-128;
  618.               if (a<r.adr) a=r.adr;
  619.               for(i=0;i<256;i++) {
  620.                 if (a==copie_de_adr) printf("\nHERE:\n");
  621.                 printf("%c",*a++);
  622.               }
  623.               printf("\n\n");
  624.               */
  625.                       }
  626.               break;
  627.             default: n=-999; printf("What did you say?\n"); break;
  628.               
  629.             } 
  630.           }
  631. #if HTS_ANALYSTE
  632. #else
  633.         } while(n==-999);
  634. #endif
  635.         io_flush;
  636.       } else {   // lien primaire: autoriser rΘpertoire entier       
  637.         if (!force_mirror) {
  638.           if ((opt->seeker & 1)==0) {  // interdiction de descendre
  639.             n=7;
  640.           } else {
  641.             n=5;   // autoriser miroir rΘpertoires descendants (lien primaire)
  642.           }
  643.         } else   // forcer valeur (sub-wizard)
  644.           n=force_mirror;
  645.       }
  646.       
  647.       /* sanity check */
  648.       if ((*filptr) + 1 >= opt->maxfilter) {
  649.         opt->maxfilter += HTS_FILTERSINC;
  650.         if (filters_init(&filters, opt->maxfilter, HTS_FILTERSINC) == 0) {
  651.           printf("PANIC! : Too many filters : >%d [%d]\n", (*filptr),__LINE__);
  652.           fflush(stdout);
  653.           if (opt->errlog) {
  654.             fprintf(opt->errlog,LF"Too many filters, giving up..(>%d)"LF, (*filptr) );
  655.             fprintf(opt->errlog,"To avoid that: use #F option for more filters (example: -#F5000)"LF);
  656.             test_flush;
  657.           }
  658.           abort();         // wild..
  659.         }
  660.         //opt->filters.filters=filters;
  661.         *ptrfilters = filters;
  662.       }
  663.  
  664.       switch(n) {
  665.       case -1: // sauter tout le reste
  666.         forbidden_url=1;
  667.         opt->wizard=2;    // sauter tout le reste
  668.         break;
  669.       case 0:    // interdire les mΩmes liens: adr/fil
  670.         forbidden_url=1; 
  671.         HT_INSERT_FILTERS0;    // insΘrer en 0
  672.         strcpybuff(filters[0],"-");
  673.         strcatbuff(filters[0],jump_identification(adr));
  674.         if (*fil!='/') strcatbuff(filters[0],"/");
  675.         strcatbuff(filters[0],fil);
  676.         break;
  677.         
  678.       case 1: // Θliminer rΘpertoire entier et sous rΘp: adr/path/ *
  679.         forbidden_url=1;
  680.         {
  681.           int i=strlen(fil)-1;
  682.           while((fil[i]!='/') && (i>0)) i--;
  683.           if (fil[i]=='/') {
  684.             HT_INSERT_FILTERS0;    // insΘrer en 0
  685.             strcpybuff(filters[0],"-");
  686.             strcatbuff(filters[0],jump_identification(adr));
  687.             if (*fil!='/') strcatbuff(filters[0],"/");
  688.             strncatbuff(filters[0],fil,i);
  689.             if (filters[0][strlen(filters[0])-1]!='/') strcatbuff(filters[0],"/");
  690.             strcatbuff(filters[0],"*");
  691.           }
  692.         }            
  693.         
  694.         // ** ...
  695.         break;
  696.         
  697.       case 2:    // adresse adr*
  698.         forbidden_url=1;
  699.         HT_INSERT_FILTERS0;    // insΘrer en 0                                
  700.         strcpybuff(filters[0],"-");
  701.         strcatbuff(filters[0],jump_identification(adr));
  702.         strcatbuff(filters[0],"*");
  703.         break;
  704.         
  705.       case 3: // ** A FAIRE
  706.         forbidden_url=1;
  707.         /*
  708.         {
  709.         int i=strlen(adr)-1;
  710.         while((adr[i]!='/') && (i>0)) i--;
  711.         if (i>0) {
  712.         
  713.           }
  714.           
  715.       }*/
  716.         
  717.         break;
  718.         //
  719.       case 4:    // same link
  720.         // PAS BESOIN!!
  721.         /*HT_INSERT_FILTERS0;    // insΘrer en 0                                
  722.         strcpybuff(filters[0],"+");
  723.         strcatbuff(filters[0],adr);
  724.         if (*fil!='/') strcatbuff(filters[0],"/");
  725.         strcatbuff(filters[0],fil);*/
  726.         
  727.         
  728.         // Θtant donnΘ le renversement wizard/primary filter (les primary autorisent up/down ET interdisent)
  729.         // il faut Θviter d'un lien isolΘ effectue un miroir total..
  730.         
  731.         *set_prio_to = 0+1;    // niveau de rΘcursion=0 (pas de miroir)
  732.         
  733.         break;
  734.         
  735.       case 5:    // autoriser rΘpertoire entier et fils
  736.         if ((opt->seeker & 2)==0) {  // interdiction de monter
  737.           int i=strlen(fil)-1;
  738.           while((fil[i]!='/') && (i>0)) i--;
  739.           if (fil[i]=='/') {
  740.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  741.             strcpybuff(filters[0],"+");
  742.             strcatbuff(filters[0],jump_identification(adr));
  743.             if (*fil!='/') strcatbuff(filters[0],"/");
  744.             strncatbuff(filters[0],fil,i+1);
  745.             strcatbuff(filters[0],"*");
  746.           }
  747.         } else {    // autoriser domaine alors!!
  748.           HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpybuff(filters[filptr],"+");
  749.           strcpybuff(filters[0],"+");
  750.           strcatbuff(filters[0],jump_identification(adr));
  751.           strcatbuff(filters[0],"*");
  752.         }
  753.         break;
  754.         
  755.       case 6:    // same domain
  756.         HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpybuff(filters[filptr],"+");
  757.         strcpybuff(filters[0],"+");
  758.         strcatbuff(filters[0],jump_identification(adr));
  759.         strcatbuff(filters[0],"*");
  760.         break;
  761.         //
  762.       case 7:    // autoriser ce rΘpertoire
  763.         {
  764.           int i=strlen(fil)-1;
  765.           while((fil[i]!='/') && (i>0)) i--;
  766.           if (fil[i]=='/') {
  767.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  768.             strcpybuff(filters[0],"+");
  769.             strcatbuff(filters[0],jump_identification(adr));
  770.             if (*fil!='/') strcatbuff(filters[0],"/");
  771.             strncatbuff(filters[0],fil,i+1);
  772.             strcatbuff(filters[0],"*[file]");
  773.           }
  774.         }
  775.         
  776.         break;
  777.         
  778.       case 50:    // on fait rien
  779.         break;
  780.       }  // switch 
  781.                               
  782.     }  // test du wizard sur l'url
  783.   }  // fin du test wizard..
  784.  
  785.   // -------------------- PHASE 5 --------------------
  786.  
  787.   // lien non autorisΘ, peut-on juste le tester?
  788.   if (just_test_it) {
  789.     if (forbidden_url==1) {
  790.       if (opt->travel&256) {    // tester tout de mΩme
  791.         if (strfield(adr,"ftp://")==0) {    // PAS ftp!
  792.           forbidden_url=1;    // oui oui toujours interdit (note: sert α rien car ==1 mais c pour comprendre)
  793.           *just_test_it=1;     // mais on teste
  794.           if ((opt->debug>1) && (opt->log!=NULL)) {
  795.             fspc(opt->log,"debug"); fprintf(opt->log,"Testing link %s%s"LF,adr,fil);
  796.           }
  797.         }
  798.       }
  799.     }
  800.     //adr[0]='\0';  // cancel
  801.   }
  802.  
  803.   // -------------------- PHASE 6 --------------------
  804. #if HTS_ANALYSTE
  805.   {
  806.     int test_url=hts_htmlcheck_check(adr,fil,forbidden_url);
  807.     if (test_url!=-1) {
  808.       forbidden_url=test_url;
  809.       may_set_prio_to=0;    // clear may-set flag
  810.     }
  811.   }
  812. #endif
  813.  
  814.   // -------------------- FINAL PHASE --------------------
  815.   // Test if the "Near" test won
  816.   if (may_set_prio_to && forbidden_url == 0) {
  817.     *set_prio_to = may_set_prio_to;
  818.   }
  819.  
  820.   return forbidden_url;
  821. }
  822.  
  823. // tester taille
  824. int hts_testlinksize(httrackp* opt,
  825.                      char* adr,char* fil,
  826.                      LLint size) {
  827.   int jok=0;
  828.   if (size>=0) {
  829.     char l[HTS_URLMAXSIZE*2];
  830.     char lfull[HTS_URLMAXSIZE*2];
  831.     if (size>=0) {
  832.       LLint sz=size;
  833.       int size_flag=0;
  834.       
  835.       // former URL complΦte du lien actuel
  836.       strcpybuff(l,jump_identification(adr));
  837.       if (*fil!='/') strcatbuff(l,"/");
  838.       strcatbuff(l,fil);
  839.       //
  840.       if (!link_has_authority(adr))
  841.         strcpybuff(lfull,"http://");
  842.       else
  843.         lfull[0]='\0';
  844.       strcatbuff(lfull,adr);
  845.       if (*fil!='/') strcatbuff(l,"/");
  846.       strcatbuff(lfull,fil);
  847.       
  848.       // tester filtres (taille)
  849.       // jok = fa_strjoker(opt->filters.filters,*opt->filters.filptr,l,&sz,&size_flag,NULL);
  850.  
  851.       // filters, 0=sait pas 1=ok -1=interdit
  852.       {
  853.         int jokDepth1=0,jokDepth2=0;
  854.         int jok1=0,jok2=0;
  855.         LLint sz1=size,sz2=size;
  856.         int size_flag1=0,size_flag2=0;
  857.         jok1  = fa_strjoker(*opt->filters.filters,*opt->filters.filptr,lfull,&sz1,&size_flag1,&jokDepth1);
  858.         jok2 =  fa_strjoker(*opt->filters.filters,*opt->filters.filptr,l,    &sz2,&size_flag2,&jokDepth2);
  859.         if (jok2 == 0) {      // #2 doesn't know
  860.           jok = jok1;        // then, use #1
  861.           sz = sz1;
  862.           size_flag = size_flag1;
  863.         } else if (jok1 == 0) {  // #1 doesn't know
  864.           jok = jok2;        // then, use #2
  865.           sz = sz2;
  866.           size_flag = size_flag2;
  867.         } else if (jokDepth1 >= jokDepth2) { // #1 matching rule is "after" #2, then it is prioritary
  868.           jok = jok1;
  869.           sz = sz1;
  870.           size_flag = size_flag1;
  871.         } else {                              // #2 matching rule is "after" #1, then it is prioritary
  872.           jok = jok2;
  873.           sz = sz2;
  874.           size_flag = size_flag2;
  875.         } 
  876.       }
  877.       
  878.  
  879.       // log
  880.       if (jok==1) {
  881.         if ((opt->debug>1) && (opt->log!=NULL)) {
  882.           fspc(opt->log,"debug"); fprintf(opt->log,"File confirmed (size test): %s%s ("LLintP")"LF,adr,fil,(LLint)(size));
  883.         }
  884.       } else if (jok==-1) {
  885.         if (size_flag) {        /* interdit α cause de la taille */
  886.           if ((opt->debug>1) && (opt->log!=NULL)) {
  887.             fspc(opt->log,"debug"); fprintf(opt->log,"File cancelled due to its size: %s%s ("LLintP", limit: "LLintP")"LF,adr,fil,(LLint)(size),(LLint)(sz));
  888.           }
  889.         } else {
  890.           jok=1;
  891.         }
  892.       }
  893.     }
  894.   }
  895.   return jok;
  896. }
  897.  
  898.  
  899.  
  900. #undef test_flush
  901. #undef urladr
  902. #undef urlfil
  903.  
  904. #undef HT_INSERT_FILTERS0
  905.  
  906.